package com.ch.d0415;

public class demo1 {
    public static void main(String[] args) {
        Thread thread = new Thread();
        // id 唯一标识,系统指定
        long id = thread.getId();
        // 线程名称,可以自定义,系统会默认命名,
        String name = thread.getName();
        // 线程优先级 : 1~10,默认为5,值越大优先级越高
        int priority = thread.getPriority();
        // 守护线程(精灵线程)标志
        boolean daemon = thread.isDaemon();

        // 静态方法: 获取当前线程对象
        Thread currentThread = Thread.currentThread();
        System.out.println(currentThread.getId());
        System.out.println(currentThread.getName());

        System.out.println("thread.getId() = " + thread.getId());
        System.out.println("thread.getName() = " + thread.getName());

        Thread t1 = new Thread("订单"){
            public void run() {
                // 获取到当前线程 t1
                Thread thread1 = Thread.currentThread();
                System.out.println("thread1.getId() = " + thread1.getId());
                System.out.println("thread1.getName() = " + thread1.getName());
            }
        };
        t1.start();

        Thread t2 = new Thread( ()->{
            for (int i = 0;i > 10000;i++) {
                System.out.println("下订单");
            }
        });

        Thread t3 = new Thread( ()->{
            for (int i = 0;i > 10000;i++) {
                System.out.println("扣库存");
            }
        });

        // 在启动线程之前设置优先级，才有效
        t2.setPriority(1);
        t3.setPriority(10);

        t2.start();
        t3.start();

        // 父子线程，默认情况下,父线程会等待所有子线程执行完成之后，才结束

    }
}
